
function BaseController(scope) {
    scope.assetsPath = function ( string )
    {
        return "assets/" + string;
    }

    scope.goHome = function()
    {
        location.href = '#/home/' + userUuid;
    }

    scope.getCategoryPage = function(category) {
        selectedCategoryUuid = category.uuid;
        location.href = "#/topics/" + category.uuid + "&&" + "" + "&&" + "";
    };

    scope.updateSearchTags = function ( tag ) {
        scope.selectedTags = updateSearchString ( tag, scope.selectedTags );
    }

    function updateSearchString ( tag, searchString )
    {
        var tags;
        if (searchString == "" ) {
            tags = [];
        } else {
            tags = searchString.split(", ");
        }
        var addTag = true;
        for (var t = 0; t < tags.length; t++) {
            if (tags[t] == tag) {
                tags.splice(t, 1);
                if (tags.length == 0)
                {
                    searchString = "";
                } else {
                    searchString = tags.join(", ");
                }
                return searchString;
            }
        }
        if (addTag) {
            tags.push(tag);
        }
        if (tags.length == 0)
        {
            searchString = "";
        } else {
            searchString = tags.join(", ");
        }
        return searchString;
    }

    scope.updateTopicTags = function ( tag )
    {
        scope.creatorTopicTags = updateSearchString ( tag, scope.creatorTopicTags );
    }

    scope.extractTopicTags = function ( tagString, array )
    {
        var uuidArray = [];
        var tagsArray = tagString.split(", ");

        for ( var t=0; t< array.length; t++ )
        {
            for ( var s=0; s< tagsArray.length; s++ )
            {
                var tag = array[t];
                if ( tag != null )
                {
                    if ( tag.name.toLowerCase() == tagsArray[s].toLowerCase() )
                    {
                        uuidArray.push( tag.uuid );
                    }
                }
            }
        }
        return uuidArray;

    }

    scope.createTopicTags = function ( tagString, array )
    {
        var uuidArray = [];
        var tagsArray = tagString.split(", ");

        for ( var t=0; t< array.length; t++ )
        {
            for ( var s=0; s< tagsArray.length; s++ )
            {
                var tag = array[t];
                if ( tag != null )
                {
                    if ( tag.name.toLowerCase() == tagsArray[s].toLowerCase() )
                    {
                        uuidArray.push( angular.copy(tag) );
                    }
                }
            }
        }
        return uuidArray;
    }

    scope.searchTags = function ( tags )
    {
        var uuidArray = scope.extractTopicTags ( tags, scope.tagsInCategory );
        scope.getTopicsForTags ( selectedCategoryUuid, uuidArray );
    }

    scope.getTopicsForTags = function ( selectedCategory, searchTags )
    {

    }

    scope.getTopicFromList = function ( tid )
    {
    }

    scope.getCategoryContainerColor = function ()
    {
        for ( var c =0; c < categories.length; c++ )
        {
            if ( categories[c].uuid+"" == selectedCategoryUuid+"" )
            {
                return "categoryContainer_" + (c+1);
            }
        }

        return "redContainer";
    }
}